import axios from "../../utils/axios"

export default {
    namespaced: true,
    state() {
        return {
            goodsList: [],
            goodsCount: 0
        }
    },
    mutations: {
        saveGoodsListMutations(state, list) {
            state.goodsList = list
        },
        saveGoodsCountMutations(state, count){
            state.goodsCount = count
        }
    },
    actions: {
        getGoodsListActions({commit}, pageInfo) {
            axios({
                method: 'GET',
                url: '/api/goodslist',
                params: pageInfo
            }).then( response => {
                commit('saveGoodsListMutations', response.list)
            } )
        },

        getGoodsCount({commit}) {
            axios({
                method: 'GET',
                url: '/api/goodscount'
            }).then( response => {
                commit('saveGoodsCountMutations', response.list[0].total||0)
            } )
        }
    },
    getters: {}
}